package com.example.demo.controller;



import com.example.demo.entity.NoteComment;
import com.example.demo.entity.NoteCreate;
import com.example.demo.service.NoteCommentService;
import com.example.demo.vo.ViewNoteCommentInfo;
import com.example.demo.vo.ViewNoteCreateInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("v1")
public class NoteCommentController {
    @Autowired
    private NoteCommentService noteCommentService;

    //笔记评论信息与用户信息相关联
    @GetMapping("/NoteCommentinfo")
    public PageInfo<ViewNoteCommentInfo> getPageNoteCommentInfo(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageInfo<ViewNoteCommentInfo> pageInfo = noteCommentService.findNoteCommentInfo(pageNum,pageSize);
        return pageInfo;
    }
    @GetMapping("/notes/pages")
    public PageInfo<NoteComment> getPageNoteComment(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageInfo<NoteComment> pageInfo = noteCommentService.findNoteCommentPages(pageNum,pageSize);
        return pageInfo;
    }

    @GetMapping("/NoteCommentinfo/{id}")
    public ViewNoteCommentInfo getNoteCommentInfo(@PathVariable Integer id) {
        return noteCommentService.findNoteCommentById(id);
    }

    //基本查询语句
    @GetMapping("/NoteComment")
    public List<NoteComment> getNoteComment() {

        return noteCommentService.findNoteCommentAll();
    }
    @GetMapping("/NoteComment/{id}")
    public NoteComment getNoteCommentId(@PathVariable Integer id) {
        return noteCommentService.findNoteCommentDyId(id);
    }

    //插入评论内容
    @PostMapping("/NoteComment")
    public Integer addNoteCommentInfo(@RequestBody NoteComment noteComment) {
        System.out.println(noteComment);
        return noteCommentService.insertNoteComment(noteComment);
    }

    @PutMapping("/NoteComment")
    public Integer updateNoteCommentInfo(@RequestBody NoteComment noteComment) {
        System.out.println(noteComment);
        return noteCommentService.updateNoteComment(noteComment);
    }
    @DeleteMapping("/NoteComment/{id}")
    public Integer deleteNoteComment(@PathVariable("id") Integer note_comment_id) {
        return noteCommentService.deleteNoteComment(note_comment_id);
    }


    //与用户表的用户名、头像相关联，且根据笔记id查找，按点赞量排序
    @GetMapping("/NoteCommentinfonoteid")
    public PageInfo<ViewNoteCommentInfo> getPageNoteCommentInfonoteid(@RequestParam Integer note_create_id) {
        PageInfo<ViewNoteCommentInfo> pageInfo = noteCommentService.findNoteCommentInfonoteid(note_create_id);
        return pageInfo;
    }

    //点击举报按钮将会把评论状态从正常修改为被举报
    @PutMapping("/NoteCommentStatus/{note_comment_id}")
    public Integer updateStatus(@PathVariable Integer note_comment_id) {
        return noteCommentService.updateStatus(note_comment_id);
    }

    //点赞
    @PostMapping("/NoteComment/like/{note_comment_id}")
    public ResponseEntity<?> likeComment(@PathVariable Integer note_comment_id) {
        noteCommentService.likeComment(note_comment_id);
        return ResponseEntity.ok().build();
    }

    //取消点赞
    @PostMapping("/NoteComment/unlike/{note_comment_id}")
    public ResponseEntity<?> unlikeComment(@PathVariable Integer note_comment_id) {
        noteCommentService.unlikeComment(note_comment_id);
        return ResponseEntity.ok().build();
    }

    //根据笔记id计数
    @GetMapping("/NoteComment/count")
    public ResponseEntity<Integer> countcomment(
            @RequestParam Integer note_create_id) {
        Integer count = noteCommentService.countcomment(note_create_id);
        return ResponseEntity.ok(count);
    }


}
